home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / joystat / joystick.bas < prev    next >
Encoding:
BASIC Source File  |  1995-05-09  |  3.5 KB  |  89 lines

  1. '   Functions for accessing the generic Joystick driver
  2. '   thanks to William Nelson at MS for converting from 'c'
  3.  
  4. Global Const MM_JOY1MOVE = &H3A0
  5. Global Const MM_JOY2MOVE = &H3A1
  6. Global Const MM_JOY1ZMOVE = &H3A2
  7. Global Const MM_JOY2ZMOVE = &H3A3
  8. Global Const MM_JOY1BUTTONDOWN = &H3B5
  9. Global Const MM_JOY2BUTTONDOWN = &H3B6
  10. Global Const MM_JOY1BUTTONUP = &H3B7
  11. Global Const MM_JOY2BUTTONUP = &H3B8
  12.  
  13. Global Const MMSYSERR_BASE = 0
  14. Global Const JOYERR_BASE = 160
  15.  
  16. ' general error return values
  17. Global Const MMSYSERR_NOERROR = 0                           ' no error
  18. Global Const MMSYSERR_ERROR = (MMSYSERR_BASE + 1)           ' unspecified error
  19. Global Const MMSYSERR_BADDEVICEID = (MMSYSERR_BASE + 2)     ' device ID out or range
  20. Global Const MMSYSERR_NOTENABLED = (MMSYSERR_BASE + 3)      ' driver failed enable
  21. Global Const MMSYSERR_ALLOCATED = (MMSYSERR_BASE + 4)       ' device aleardy allocated
  22. Global Const MMSYSERR_INVALHANDLE = (MMSYSERR_BASE + 5)     ' device handle is invalid
  23. Global Const MMSYSERR_NODRIVER = (MMSYSERR_BASE + 6)        ' no device driver present
  24. Global Const MMSYSERR_NOMEM = (MMSYSERR_BASE + 7)           ' memory allocation error
  25. Global Const MMSYSERR_NOTSUPPORTED = (MMSYSERR_BASE + 8)    ' function isn't supported
  26. Global Const MMSYSERR_BADERRNUM = (MMSYSERR_BASE + 9)       ' error value out of range
  27. Global Const MMSYSERR_INVALFLAG = (MMSYSERR_BASE + 10)      ' invalid flag passed
  28. Global Const MMSYSERR_INVALPARAM = (MMSYSERR_BASE + 11)     ' invalid parameter passsed
  29. Global Const MMSYSERR_LASTERROR = (MMSYSERR_BASE + 12)      ' last error in range
  30.  
  31. ' joystick error return values
  32. Global Const JOYERR_NOERROR = 0                     ' no error
  33. Global Const JOYERR_PARMS = (JOYERR_BASE + 5)       ' bad parameters
  34. Global Const JOYERR_NOCANDO = (JOYERR_BASE + 6)     ' request not completed
  35. Global Const JOYERR_UNPLUGGED = (JOYERR_BASE + 7)   ' joystick is unplugged
  36.  
  37. ' constants used with JOYINFO structure and MM_JOY messages
  38. Global Const JOY_BUTTON1 = &H1
  39. Global Const JOY_BUTTON2 = &H2
  40. Global Const JOY_BUTTON3 = &H4
  41. Global Const JOY_BUTTON4 = &H8
  42. Global Const JOY_BUTTON1CHG = &H100
  43. Global Const JOY_BUTTON2CHG = &H200
  44. Global Const JOYSTICKID1 = 0
  45. Global Const JOYSTICKID2 = 1
  46.  
  47. Type JOYCAPS
  48.     wMid As Integer
  49.     wPid As Integer
  50.     sxPname As String * 256
  51.     wXmin As Integer
  52.     wXmax As Integer
  53.     wYmin As Integer
  54.     wYmax As Integer
  55.     wZmin As Integer
  56.     wZmax As Integer
  57.     wNumButtons As Integer
  58.     wPeriodMin As Integer
  59.     wPeriodMax As Integer
  60. End Type
  61.  
  62. Type JOYINFO
  63.     wXPos As Integer
  64.     wYPos As Integer
  65.     wZPos As Integer
  66.     wButtons As Integer
  67. End Type
  68.  
  69. Declare Function joyGetDevCaps Lib "MMSYSTEM" (ByVal wJoyID%, lpCaps As JOYCAPS, ByVal wSize%) As Integer
  70. Declare Function JoyGetNumDevs Lib "MMSYSTEM" () As Integer
  71. Declare Function joyGetPos Lib "MMSYSTEM" (ByVal wJoyID%, lpInfo As JOYINFO) As Integer
  72. Declare Function joyGetThreshold Lib "MMSYSTEM" (ByVal wJoyID%, lpwThreshold%) As Integer
  73. Declare Function joyReleaseCapture Lib "MMSYSTEM" (ByVal wJoyID%) As Integer
  74. Declare Function joySetThreshold Lib "MMSYSTEM" (ByVal wJoyID%, ByVal wThreshold%) As Integer
  75. Declare Function joySetCapture Lib "MMSYSTEM" (ByVal wHnd%, ByVal wJoyID%, ByVal wPeriod%, ByVal bChanged%) As Integer
  76.  
  77. Function Long2w (LongValue As Long) As Integer
  78.  
  79.     Long2w = CInt(LongValue - &H10000)
  80.  
  81. End Function
  82.  
  83. Function w2Long (wUINT As Integer) As Long
  84.  
  85.     w2Long = (CLng(wUINT) And &HFFFF&)
  86.  
  87. End Function
  88.  
  89.